
package com.insigma.business.qrcode.soldier.service;



import com.insigma.business.qrcode.common.service.SequenceGenerator;
import com.insigma.business.qrcode.soldier.dao.PlacementThroughTrainApplyInfoDao;
import com.insigma.business.qrcode.soldier.dto.PlacementThroughTrainApplyInfoBSearcher;
import com.insigma.business.qrcode.soldier.dto.SequenceNameConstant;
import com.insigma.business.qrcode.soldier.entity.PlacementThroughTrainApplyInfoDO;
import org.apache.commons.httpclient.util.DateUtil;
import org.apache.logging.log4j.util.Strings;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;


@Service("placementThroughTrainApplyInfoService")
public class PlacementThroughTrainApplyInfoServiceImpl implements PlacementThroughTrainApplyInfoService {

    @Autowired(required = false)
    private PlacementThroughTrainApplyInfoDao placementThroughTrainApplyInfoDao;
    @Autowired(required = false)
    private SequenceGenerator sequenceGenerator;
    @Autowired
    private PlacementSoldierInfoService placementSoldierInfoService;
    
    @Override
    public List<PlacementThroughTrainApplyInfoDO> search(final PlacementThroughTrainApplyInfoBSearcher placementThroughTrainApplyInfoBSearcher) {
        if (Strings.isBlank(placementThroughTrainApplyInfoBSearcher.getYear())) {
            String year = DateUtil.formatDate(new Date(), "yyyy");
            placementThroughTrainApplyInfoBSearcher.setYear(year);
        }
        return placementThroughTrainApplyInfoDao.search(placementThroughTrainApplyInfoBSearcher);
    }
   
    @Override
    public PlacementThroughTrainApplyInfoDO get(final String id){
        return placementThroughTrainApplyInfoDao.get(id);
    }

    
    @Override
    public Integer insert(final PlacementThroughTrainApplyInfoDO placementThroughTrainApplyInfoDO){
        placementThroughTrainApplyInfoDO.setId(sequenceGenerator.genKey(SequenceNameConstant.PLACEMENT_THROUGH_TRAIN_APPLY_INFO_ID));
        return placementThroughTrainApplyInfoDao.insert(placementThroughTrainApplyInfoDO);
    }

    
    @Override
    public Integer update(final PlacementThroughTrainApplyInfoDO placementThroughTrainApplyInfoDO){
        return placementThroughTrainApplyInfoDao.update(placementThroughTrainApplyInfoDO);
    }

    
    @Override
    public Integer delete(final String id, final String modifierType, final String modifierId){
        return placementThroughTrainApplyInfoDao.delete(id,modifierType,modifierId);
    }

    @Override
    public PlacementThroughTrainApplyInfoDO getBySoldierId(String soldierId) {
        String idCardNo = placementSoldierInfoService.getIdCardNoBySoldierId(soldierId);
        return placementThroughTrainApplyInfoDao.getByIdCardNo(idCardNo);
    }

    @Override
    public PlacementThroughTrainApplyInfoDO getByIdCardNo(String idCardNo) {
        return placementThroughTrainApplyInfoDao.getByIdCardNo(idCardNo);
    }

    @Override
    public Integer count(PlacementThroughTrainApplyInfoBSearcher placementThroughTrainApplyInfoBSearcher) {
        search(placementThroughTrainApplyInfoBSearcher);
        return Long.valueOf(placementThroughTrainApplyInfoBSearcher.getTotalCount()).intValue();
    }


}
